<?php
if (!defined('QUADODO_IN_SYSTEM')) {
exit;	
}

/**
 * Acts as an interface for the sub classes
 */
class SQL {

/**
 * @var object $qls - Will contain everything else
 */
var $qls;

	/**
	 * Constructs the class
	 * @param object $qls - Contains all the other classes
	 * @return void but will output error if found
	 */
	function SQL(&$qls) {
	$this->qls = &$qls;

	require_once('database_info.php');
	$this->database_type = $database_type;
	$this->qls->config['sql_prefix'] = $database_prefix;

	// Get the actual database class
	$database_file = ($database_type == 'MySQLi') ? 'MySQLie' : $database_type;
	require_once($database_file . '.class.php');
		switch ($database_type) {
			// Default is MySQL
			default:
			case 'MySQL':
			// Construct the class, and add to $current_layer
			$this->current_layer = new MySQL($database_server_name,
				$database_username,
				$database_password,
				$database_name,
				$database_persistent,
				$this->qls,
				$database_port
			);
			break;
			case 'MySQLi':
			$this->current_layer = new MySQLie($database_server_name, 
				$database_username,
				$database_password,
				$database_name,
				$this->qls,
				$database_port
			);
			break;
			case 'PostgreSQL':
			$this->current_layer = new PostgreSQL($database_server_name,
				$database_username,
				$database_password,
				$database_name,
				$database_persistent,
				$this->qls,
				$database_port
			);
			break;
		}
	}

	/**
	 * These functions run the functions in the database classes. See those 
	 * files for more information.
	 */
	function update_queries() {
	$this->current_layer->update_queries();
	}

	function affected_rows() {
	return $this->current_layer->affected_rows();
	}

	function fetch_row($result) {
	return $this->current_layer->fetch_row($result);
	}

	function fetch_assoc($result) {
	return $this->current_layer->fetch_assoc($result);
	}

	function fetch_array($result) {
	return $this->current_layer->fetch_array($result);
	}

	function free_result($result) {
	return $this->current_layer->free_result($result);
	}

	function get_client_info() {
	return $this->current_layer->get_client_info();
	}

	function insert_id() {
	return $this->current_layer->insert_id();
	}

	function num_fields($result) {
	return $this->current_layer->num_fields($result);
	}

	function num_rows($result) {
	return $this->current_layer->num_rows($result);
	}

	function transaction($status = 'BEGIN') {
	return $this->current_layer->transaction($status);
	}

	function select($what, $from, $where = false, $order_by = false, $limit = false) {
	return $this->current_layer->select($what, $from, $where, $order_by, $limit);
	}

	function delete($from, $where) {
	return $this->current_layer->delete($from, $where);
	}

	function update($table, $set, $where) {
	return $this->current_layer->update($table, $set, $where);
	}

	function insert($table, $columns, $values) {
	return $this->current_layer->insert($table, $columns, $values);
	}

	function alter($table, $action, $column, $data_type = false, $null = false) {
	return $this->current_layer->alter($table, $action, $column, $data_type, $null);
	}

	function query($query) {
	return $this->current_layer->query($query);
	}

	function close() {
	return $this->current_layer->close();
	}
}
?>